package com.chinasi.web.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.caland.framework.core.page.Pager;
import com.chinasi.common.EntityType;
import com.chinasi.model.ConsumerBasic;
import com.chinasi.service.BidConsumerService;
import com.chinasi.service.ConsumerBasicService;
import com.chinasi.web.action.common.URLConstants;

/**
 * 产业实体：项目甲方
 * @author xzl
 *
 */
@Controller
@RequestMapping(value = URLConstants.CONSUMER)
public class ConsumerBasicAction {

	/**
	 * ConsumerBasicService
	 */
	@Autowired
	private ConsumerBasicService consumerBasicService;
	
	@Autowired
	private BidConsumerService bidConsumerService;
	
	/** 列表检索页面 */
	@RequestMapping("list")
	public ModelAndView list(ConsumerBasic searchBean, HttpServletRequest request){
		Pager pager = consumerBasicService.findPageCondition(searchBean,1);
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		model.put("params", searchBean);
		model.put("entityType", EntityType.CONSUMER.toString());
		model.put("menu", "CYDA");
		return new ModelAndView("cyst/consumer_list",model);
	}
	
	/** 异步加载分页数据 */
	@RequestMapping("loadajax")
	public ModelAndView loadajax(HttpServletRequest request, HttpServletResponse response,ConsumerBasic searchBean, int curpage){
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", consumerBasicService.findPageCondition(searchBean,curpage));
		return new ModelAndView("fragment/fragment_consumer_more", model);
	}
	
	/** 基本信息 */
	@RequestMapping("baseInfo")
	public ModelAndView baseInfo(String id){
		ConsumerBasic consumer = consumerBasicService.findById(id);
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("consumer", consumer);
		return new ModelAndView("cyst/consumer/baseinfo", model);
	}
	
	/** 实施项目 */
	@RequestMapping("implement_project")
	public ModelAndView implementProject(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsumerBasic consumer = consumerBasicService.findById(id);
		
		//甲方实施项目列表
		Pager pager = bidConsumerService.findRelationBid(consumer.getConCode(), currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consumer", consumer);
		return new ModelAndView("cyst/consumer/implement_project", model);
	}
	
	/** 相关咨询机构 */
	@RequestMapping("rel_consult")
	public ModelAndView relConsult(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsumerBasic consumer = consumerBasicService.findById(id);

		Pager pager = bidConsumerService.findRelationConsult(consumer, currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consumer", consumer);
		return new ModelAndView("cyst/consumer/rel_consult", model);
	}
	
	/** 相关集成商*/
	@RequestMapping("rel_integration")
	public ModelAndView relIntegration(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsumerBasic consumer = consumerBasicService.findById(id);
		
		Pager pager = bidConsumerService.findRelationIntegrator(consumer, currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consumer", consumer);
		return new ModelAndView("cyst/consumer/rel_integration", model);
	}
	
	/** 相关招标代理*/
	@RequestMapping("rel_agency")
	public ModelAndView relAgency(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsumerBasic consumer = consumerBasicService.findById(id);
		
		Pager pager = bidConsumerService.findRelationAgency(consumer, currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consumer", consumer);
		return new ModelAndView("cyst/consumer/rel_agency", model);
	}
	
	/** 相关招标代理*/
	@RequestMapping("rel_supervision")
	public ModelAndView relSupervision(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsumerBasic consumer = consumerBasicService.findById(id);
		
		Pager pager = bidConsumerService.findRelationSupervision(consumer, currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consumer", consumer);
		return new ModelAndView("cyst/consumer/rel_supervision", model);
	}
	
	/** 合作专家*/
	@RequestMapping("rel_expert")
	public ModelAndView relExpert(String id, @RequestParam(defaultValue="1") int currentPage){
		
		ConsumerBasic consumer = consumerBasicService.findById(id);
		
		Pager pager = bidConsumerService.findRelationExpert(consumer, currentPage);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("pager", pager);
		Map<String,String> params = new HashMap<String, String>();
		params.put("id", id);
		model.put("params", params);
		model.put("consumer", consumer);
		return new ModelAndView("cyst/consumer/rel_expert", model);
	}
}
